package com.my.demo.projectService;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/config")
public class ConfigController {

	@RequestMapping("/set")
	@PreAuthorize("hasAuthority('USER')")
	public Object set(Authentication authentication) {
		authentication.getAuthorities();
		OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
		String token = details.getTokenValue();
		return token + "config project have authorization";
	}

	@RequestMapping("/get")
	@PreAuthorize("hasAuthority('PROJECT')")
	public String get() {
		return "config project";
	}
}